﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using CSharp.Libs.Koc.Models;
using CSharp.Libs.WPF;

namespace CSharp.Libs.Koc.UserControls.ItemClasses
{
    public class UserProfileItem : ViewModelBase
    {
        #region declarations
        private String _strallianceId = "";
        private String _strglory = "";
        private Double _dblmight = 0;
        private String _strplayerSex = "";
        private String _strwarStatus = "";
        private String _struserId = "";
        private String _strdisplayName = "";
        private String _stravatarId = "";
        private String _strtitle = "";
        private String _strallianceName = "";
        private String _strmaxGlory = "";
        #endregion



        #region constructor / terminator
        public UserProfileItem()
        {
            UVI = new UserValidatorItem();
        }

        public UserProfileItem(
            Kernel KRNL,
            Hashtable htUserProfile)
        {
            UVI = new UserValidatorItem();
            _analyzeHashtable(KRNL, htUserProfile);
        }

        public UserProfileItem(
            Kernel KRNL,
            Hashtable htUserProfile,
            UserValidatorItem uviUser)
            : this(KRNL, htUserProfile)
        {
            UVI = uviUser;
        }
        #endregion



        #region event handling
        #endregion



        #region private functions
        /// <summary>_clear</summary>
        /// <history>created  09.02.2012</history>
        private void _clear()
        {
            _strallianceId = "";
            _strglory = "";
            _dblmight = 0;
            _strplayerSex = "";
            _strwarStatus = "";
            _struserId = "";
            _strdisplayName = "";
            _stravatarId = "";
            _strtitle = "";
            _strallianceName = "";
            _strmaxGlory = "";
        }

        /// <summary>_GetCopy</summary>
        /// <param name="upiSource"></param>
        /// <returns></returns>
        /// <history>created  23.02.2012</history>
        private UserProfileItem _GetCopy()
        {
            try
            {
                UserProfileItem upiDestination = new UserProfileItem();

                upiDestination.allianceId= _strallianceId;
                upiDestination.glory = _strglory;
                upiDestination.might = _dblmight = 0;
                upiDestination.playerSex = _strplayerSex;
                upiDestination.warStatus = _strwarStatus;
                upiDestination.userId = _struserId;
                upiDestination.displayName = _strdisplayName;
                upiDestination.avatarId = _stravatarId;
                upiDestination.title = _strtitle;
                upiDestination.allianceName = _strallianceName;
                upiDestination.maxGlory = _strmaxGlory;

                return upiDestination;
            }
            catch (Exception ex)
            {
                //throw ex;
            }

            return null;
        }

        /// <summary>_analyzeHashtable</summary>
        /// <param name="KRNL"></param>
        /// <param name="htUserProfile"></param>
        /// <history>created  09.02.2012</history>
        private void _analyzeHashtable(
            Kernel KRNL,
            Hashtable htUserProfile)
        {
            _strallianceId = KRNL.GetHashtableValue(htUserProfile, constants.KEY_ALLIANCE_ID, KernelTools.VariableTypes.String);
            _strglory = KRNL.GetHashtableValue(htUserProfile, constants.KEY_GLORY, KernelTools.VariableTypes.String);
            _dblmight = KRNL.GetHashtableValue(htUserProfile, constants.KEY_MIGHT, KernelTools.VariableTypes.Double);
            _strplayerSex = KRNL.GetHashtableValue(htUserProfile, constants.KEY_PLAYER_SEX, KernelTools.VariableTypes.String);
            _strwarStatus = KRNL.GetHashtableValue(htUserProfile, constants.KEY_WAR_STATUS, KernelTools.VariableTypes.String);
            _struserId = KRNL.GetHashtableValue(htUserProfile, constants.KEY_USER_ID, KernelTools.VariableTypes.String);
            _strdisplayName = KRNL.GetHashtableValue(htUserProfile, constants.KEY_DISPLAY_NAME, KernelTools.VariableTypes.String);
            _stravatarId = KRNL.GetHashtableValue(htUserProfile, constants.KEY_AVATAR_ID, KernelTools.VariableTypes.String);
            _strtitle = KRNL.GetHashtableValue(htUserProfile, constants.KEY_TITLE, KernelTools.VariableTypes.String);
            _strallianceName = KRNL.GetHashtableValue(htUserProfile, constants.KEY_ALLIANCE_NAME, KernelTools.VariableTypes.String);
            _strmaxGlory = KRNL.GetHashtableValue(htUserProfile, constants.KEY_MAX_GLORY, KernelTools.VariableTypes.String);

            OnPropertyChanged("PlayerNameFbUid");
            OnPropertyChanged("allianceId");
            OnPropertyChanged("glory");
            OnPropertyChanged("might");
            OnPropertyChanged("playerSex");
            OnPropertyChanged("warStatus");
            OnPropertyChanged("userId");
            OnPropertyChanged("displayName");
            OnPropertyChanged("avatarId");
            OnPropertyChanged("title");
            OnPropertyChanged("allianceName");
            OnPropertyChanged("maxGlory");
        }
        #endregion



        #region interface
        #region properties
        public UserValidatorItem UVI
        {
            get;
            set;
        }
        public string FbUid
        {
            get
            {
                return UVI.FbUid;
            }
        }
        public bool UserIsValid
        {
            get
            {
                return UVI.UserIsValid;
            }
        }
        public int LastCheckedTimestamp
        {
            get
            {
                return UVI.LastCheckedTimestamp;
            }
        }

        public string PlayerNameFbUid
        {
            get
            {
                return string.Concat(displayName, " (FBUID: ", FbUid, ")");
            }
        }

        public String allianceId
        {
            get
            {
                return _strallianceId;
            }
            set
            {
                _strallianceId = value;
            }
        }

        public String glory
        {
            get
            {
                return _strglory;
            }
            set
            {
                _strglory = value;
            }
        }

        public Double might
        {
            get
            {
                return _dblmight;
            }
            set
            {
                _dblmight = value;
            }
        }

        public String playerSex
        {
            get
            {
                return _strplayerSex;
            }
            set
            {
                _strplayerSex = value;
            }
        }

        public String warStatus
        {
            get
            {
                return _strwarStatus;
            }
            set
            {
                _strwarStatus = value;
            }
        }

        public String userId
        {
            get
            {
                return _struserId;
            }
            set
            {
                _struserId = value;
            }
        }

        public String displayName
        {
            get
            {
                return _strdisplayName;
            }
            set
            {
                _strdisplayName = value;
            }
        }

        public String avatarId
        {
            get
            {
                return _stravatarId;
            }
            set
            {
                _stravatarId = value;
            }
        }

        public String title
        {
            get
            {
                return _strtitle;
            }
            set
            {
                _strtitle = value;
            }
        }

        public String allianceName
        {
            get
            {
                return _strallianceName;
            }
            set
            {
                _strallianceName = value;
            }
        }

        public String maxGlory
        {
            get
            {
                return _strmaxGlory;
            }
            set
            {
                _strmaxGlory = value;
            }
        }
        #endregion

        #region methods
        public void Clear()
        {
            _clear();
        }

        /// <summary>returns a new instance (copy) of UserProfileItem with the data of the current instance</summary>
        /// <returns>UserProfileItem</returns>
        /// <history>created  23.02.2012</history>
        public UserProfileItem GetCopy()
        {
            return _GetCopy();
        }

        public void AnalyzeHashtable(
            Kernel KRNL,
            Hashtable htUserProfile)
        {
            _analyzeHashtable(KRNL, htUserProfile);
        }
        #endregion
        #endregion
    }
}
